<?php

class Admin_Models_User extends Libs_Model {

    private $user_id;
    private $email;
    private $full_name;
    private $password;
    private $phone;

    function __construct() {
        parent::__construct();
    }

    public function setUserId($user_id) {
        $this->user_id = $user_id;
    }

    public function getUserId() {
        return $this->user_id;
    }

    public function setEmail($email) {
        $this->email = $email;
    }

    public function getEmail() {
        return $this->email;
    }

    public function setFullName($full_name) {
        $this->full_name = $full_name;
    }

    public function getFullName() {
        return $this->full_name;
    }

    public function setPassword($password) {
        $this->password = $password;
    }

    public function getPassword() {
        return $this->password;
    }

    public function setPhone($phone) {
        $this->phone = $phone;
    }

    public function getPhone() {
        return $this->phone;
    }

    public function setValue($row, $isKey = true) {
        $user = new Admin_Models_User();
        if ($isKey) {
            $user->setUserId($row['user_id']);
        }
        $user->setEmail($row['email']);
        $user->setFullName($row['full_name']);
        $user->setPassword($row['password']);
        $user->setPhone($row['phone']);
        return $user;
    }

    public function getKeyAndValue(Admin_Models_User $user, $isKey = false) {
        $data = array();
        if ($isKey) {
            $data['user_id'] = $this->getUserId();
        }
        $data['email'] = $this->getEmail();
        $data['full_name'] = $this->getFullName();
        $data['password'] = $this->getPassword();
        $data['phone'] = $this->getPhone();
    }

    public function checkUserLogin($e, $p) {
        $sql = "select * from tbl_users where email = '$e' and password = '$p'";
        return $this->db->fetchOne($sql);
    }

    public function checkPass($email, $op) {
        $sql = "select * from tbl_users where email = '$email' and password = '$op'";
        $result = $this->db->fetchOne($sql);
        if (!empty($result)) {
            return true;
        } else {
            return false;
        }
    }

    public function changePass($email, $np) {
        $sql = "update tbl_users set password = '$np' where email = '$email'";
        $this->db->query($sql);
    }

}
